package com.itheima.flowcontrol.demo;

import java.util.Scanner;

/**
 * 简单计算器 实现加减乘除 + - * /
 */
public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数字1: ");
        double num1 = sc.nextDouble();
        System.out.println("请输入数字2：");
        double num2 = sc.nextDouble();
        System.out.println("请输入运算符：");
        String operator = sc.next();
        System.out.println("运算结果为："+ calc(num1, num2, operator));

    }
    public static double calc(double num1, double num2,String operator) {
        //1.输入不同的数字和运算符 输出不同的结果 switch分支
        double result = 0;
        switch (operator) {
            case"+":
                 result = num1 + num2;
                break;
            case "-":
                result = num1 - num2;
                break;
            case "*":
                result = num1 * num2;
                break;
            case "/":
                result = num1 / num2;
                break;
        }
        return result;
    }
}

